package ck.springboot.utils;

import io.swagger.models.auth.In;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.ArrayList;
import java.util.List;

/**
 * @Classname DateUtils
 * @Description TODO
 * @Date 2021/12/1 15:19
 * @Created by lpc
 */
public class DateUtils {

    /**
     * 日期类型转化字符串
     * @param localDate
     * @param pattern
     * @return
     */
   public static String  parseDate(LocalDate localDate ,String pattern){
       DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
       return localDate.format(dateTimeFormatter);
   }

    /**
     * 获取每月的所有日期，日期格式为：yyyyMMdd
     * @param cycle  例如：201910
     * @return 返回集合日期
     */
   public static List<Integer> getMonthDays(Integer cycle){
       List<Integer> monthDays = new ArrayList<Integer>();
       int startNum = 1;

       LocalDate localDate = LocalDate.parse(cycle + "01", DateTimeFormatter.ofPattern("yyyyMMdd"));

       System.out.println("localDate为：" + localDate);

       int lastNum = localDate.with(TemporalAdjusters.lastDayOfMonth()).getDayOfMonth();
       System.out.println("lastNum为：" + lastNum);

       Integer firstDay = new Integer(localDate.format(DateTimeFormatter.BASIC_ISO_DATE));
       System.out.println("firstDay为：" + firstDay);

       for (int i = startNum; i <= lastNum; i++) {

           monthDays.add(firstDay);
           firstDay++;
       }


       System.out.println("monthDays为：" + monthDays);
       return monthDays;
   }



    public static void main(String[] args) {
        LocalDate localDate = LocalDate.now();
        System.out.println(parseDate( LocalDate.now(),"yyyyMMdd"));
        System.out.println(localDate);
    }
}
